package com.kristou.urgdroid;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Log;

import com.android.looper.DrawableObject;

import java.util.ArrayList;

/**
 * Created by Kristou on 13/10/03.
 */
public class MeasurementObject implements DrawableObject {

    private static final String TAG = MeasurementObject.class.getSimpleName();

    private PointF mCenter = new PointF(0, 0);
    private int width = 0;
    private int height = 0;
    private Paint paint = new Paint();
    private ArrayList<PointF> mData = new ArrayList<PointF>();
    private float mScaleFactor;

    @Override
    public void setCenter(float x, float y) {
        mCenter.set(x, y);
    }

    @Override
    public void setCenter(PointF center) {
        mCenter = center;
    }

    @Override
    public void setScaleFactor(float zoomFactor) {
        mScaleFactor = zoomFactor;
    }

    @Override
    public Rect[] draw(Canvas canvas) {

        for (PointF p : mData) {
            canvas.drawLine(mCenter.x, mCenter.y, mCenter.x + (p.x * mScaleFactor), mCenter.y + (p.y * mScaleFactor), paint);
        }

        // Returns the bounds of the drawing
        return new Rect[]{new Rect(
                (int) mCenter.x, (int) mCenter.y,
                (int) mCenter.x + width, (int) mCenter.y + height)};
    }

    public void setData(ArrayList<PointF> data) {
        this.mData = data;
        Log.i(TAG, "Data received");
    }

    public void setColor(int color) {
        paint.setColor(color);
    }
}
